package com.example.c3p0.servlet; /**
 * @auther 尚智江
 * @Date 2022/5/15 15:26
 */

import com.example.c3p0.dao.UserDao;
import com.example.c3p0.dao.UserDaoImpl;
import com.example.c3p0.javabean.User;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.SQLException;

@WebServlet(name = "NoteServlet", value = "/NoteServlet")
public class NoteServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // 设置请求编码，相应方式和编码方式
        response.setCharacterEncoding("UTF-8");
        request.setCharacterEncoding("UTF-8");
        response.setContentType("text/html");
        // 获取注册页面提交的数据
        String noteUsername = request.getParameter("username");
        String notePassword = request.getParameter("password");
        User user = new User();
        UserDao userDao = new UserDaoImpl();
        if(noteUsername!=null&&notePassword!=null){
            user.setUsername(noteUsername);
            user.setPassword(notePassword);
            try {
                userDao.insertUser(user);
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
    }
}
